package routefinder;

import routefinder.exception.RouteFinderException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * A convenience class to access the properties for the application.
 *
 * @author Lucas
 */
public class Configuration {

    private static Properties prop;
    private static Configuration instance;

    public static Configuration getInstance() throws RouteFinderException {
        if(instance == null){
            instance = new Configuration();
        }
        return instance;
    }

    private Configuration() throws RouteFinderException {
        try {
            prop = new Properties();            
            prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"));
        } catch (FileNotFoundException fnfEx) {
            throw new RouteFinderException("Couldn't load properties", fnfEx);
        } catch (IOException ioEx) {
            throw new RouteFinderException("Couldn't load properties", ioEx);
        }
    }

    public String getProperty(String propKey) {
        return prop.getProperty(propKey);
    }

    public int getPropertyAsInt(String propKey) {
        return Integer.parseInt(getProperty(propKey));
    }
}
